package com.wenhao.ctrip;

import java.util.*;
import java.util.logging.SocketHandler;

/**
 * @author Wenhao Tong
 * @create 2021-09-09 19:32
 */
public class Main3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        String s = scanner.next();
        Map<Integer,Integer> map = new HashMap<>();
        int count = 0;
        int maxCount = 0;
        for (int i = 0;i < n;i++) {
            if (s.charAt(i) == '0') {
                if (map.containsKey(count)) {
                    map.put(count,map.get(count) + 1);
                } else {
                    map.put(count,1);
                }
                maxCount = Math.max(maxCount,count);
                count = 0;
            } else {
                count++;
            }
        }
        if (count > 0) {
            if (map.containsKey(count)) {
                map.put(count,map.get(count) + 1);
            } else {
                map.put(count,1);
            }
            maxCount = Math.max(maxCount,count);
        }
        long[] score = new long[Math.max(maxCount + 1,101)];
        for (int i = 0;i < m;i++) {
            int temp = scanner.nextInt();
            score[temp] = scanner.nextInt();
        }
        for (int i = 0;i < score.length && i <= maxCount;i++) {
            for (int j = 1;j < i / 2 + 1;j++) {
                score[i] = Math.max(score[j] + score[i - j],score[i]);
            }
        }
        int result = 0;
        for (Map.Entry<Integer,Integer> entry : map.entrySet()) {
            result += score[entry.getKey()] * entry.getValue();
        }
        System.out.println(result);
    }
}
